package com.example.bgxqactivityservice.interceptor;

import com.example.bgxqapi.util.LogUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * taskId拦截器
 * @author lizijian
 */
@Component
@Slf4j
public class LogInterceptor extends HandlerInterceptorAdapter {

  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
      throws Exception {
    String taskId = request.getHeader("task_id");
    log.info("taskId:"+taskId);
    if(taskId!=null){
      LogUtil.setTaskId(taskId);
    }
    return true;
  }

}
